<template>
  <ex_super_dialog_form ref="reportDialog" v-bind="report_dialog" v-on="$listeners">
  </ex_super_dialog_form>
</template>
<script>
import anomaly_desc_select from '@/component/common/anomaly_desc_select.vue'

export default {
  components: {anomaly_desc_select},
  props: {

    orderTypeList: {
      type: Array,
      default: () => []
    },

    extraModel: {
      type: Array,
      default: () => []
    },
  },
  data() {
    return {
      disabledEditInfo: false,
      report_dialog: {
        customClass: 'dialog_auto',
        submitDataHandle: (data) => {
          const { attachedList, ...other } = data
          if (attachedList) other.anomalyAttachedList = attachedList
          return other
        },
        submitUrl: this.$url['oms/BaseAnomalyReport'],
        detailUrl: this.$url['oms/BaseAnomalyDetail'],

        form: {
          itemClass: "form_item_default", inputClass: "form_input_default",
          formClass: "form_default_col2 flex_row_wrap",
          default: {},
          model: [
            { header: "label_base_info", },

            ...this.extraModel,
            {
              key: 'orderType', label: 'label_order_type', type: 'select',
              formType: () => this.disabledEditInfo ? 'text' : '',
              formatter: (r, c, v, i) => this.$enumShow(v, "AbnormalOrderTypeEnum"),
              attrs: {
                enum: 'AbnormalOrderTypeEnum',
                listHandler: (list) => {
                  if (this.orderTypeList.length > 0) return this.orderTypeList
                  return list
                }
              }
            },
            {
              key: 'orderNo', label: 'label_order_code',
              formType: () => this.disabledEditInfo ? 'text' : '',
              attrs: { maxlength: 30, 'show-word-limit': true }
            },
            {
              key: "anomalyDescribeId",
              label: "label_anomaly_desc", render: (h, { data }) => {
                return h(anomaly_desc_select, {
                  class: 'form_input_default',
                  props: {
                    classify: data.anomalyClassifyId,
                    describe: data.anomalyDescribeId,
                    classifyName: data.anomalyClassifyName,
                    describeName: data.anomalyDescribeName,
                    processNodeList: ['PICK_UP', 'DELIVERY', 'COMMON'],
                  },
                  on: {
                    'classifyItem': (e) => {
                      if (!e) e = { id: null, name: null }
                      this.$set(data, 'anomalyClassifyId', e.id)
                      this.$set(data, 'anomalyClassifyName', e.name)
                    },
                    'describeItem': (e) => {
                      if (!e) e = { id: null, name: null }
                      this.$set(data, 'anomalyDescribeId', e.id)
                      this.$set(data, 'anomalyDescribeName', e.name)
                    },
                  }
                })


              }
            },
            // { key: 'anomalyCause', label: 'label_reason_abnormal', type: 'select', attrs: { enum: 'AnomalyCauseEnum' } },
            {
              key: 'anomalyOccurrenceDate', label: 'label_abnormal_happen_time', type: 'date-picker',
              attrs: { clearable: false, type: "datetime", },
            },
            { key: 'anomalyBoxQty', label: 'label_abnormal_box_count', attrs: { maxlength: 9, 'show-word-limit': true } },
            { key: 'anomalySkuQty', label: 'label_abnormal_piece_count', attrs: { maxlength: 9, 'show-word-limit': true } },
            { key: 'anomalySkuValue', label: 'label_abnormal_sku_value', attrs: { maxlength: 9, 'show-word-limit': true } },
            { key: 'anomalyRemark', label: 'label_abnormal_remark', attrs: { maxlength: 50, 'show-word-limit': true } },
            {
              key: 'attachedList', label: 'label_abnormal_attachment', type: 'upload-file', attrs: { limit: 3 },
              render: (h, { data }) => {
                return h('ex-upload-file', {
                  props: {
                    limit: 3,
                    value: data.attachedList
                  },
                  on: {
                    input: (list) => {
                      this.$set(data, 'attachedList', list.map(it => {
                        it.type = 'ABNORMAL'
                        return it
                      }))
                    }
                  }
                },)
              }

            },

          ],
          rules: {
            // 'customerId': { required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' },
            'anomalyDescribeId': { required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' },
            'orderType': { required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' },
            'orderNo': { required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' },
            'anomalyBoxQty': {
              required: true, trigger: 'blur',
              validator: (r, v, cb) => {
                if (_.isEmpty(v)) {
                  cb(this.$tt('tip_can_no_empty'))
                } else if (!this.$reg.PureNumber(v)) {
                  cb(this.$tt("tip_only_positive_pure_decimal"))
                } else {
                  cb()
                }
              }
            },
            'anomalySkuQty': {
              required: true, trigger: 'blur',
              validator: (r, v, cb) => {
                if (_.isEmpty(v)) {
                  cb(this.$tt('tip_can_no_empty'))
                } else if (!this.$reg.PureNumber(v)) {
                  cb(this.$tt("tip_only_positive_pure_decimal"))
                } else {
                  cb()
                }
              }
            },

            // 'anomalySkuValue': {
            //   required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur',
            //   validator: (r, v, cb) => {
            //     if (_.isEmpty(v)) {
            //       cb(this.$tt('tip_can_no_empty'))
            //     } else if (!this.$reg.DigitNumber(v, 2, 9)) {
            //       cb(this.$tt("tip_check_decimal_digit_int", { digit: 2, int: 9 }))
            //     } else {
            //       cb()
            //     }
            //   }
            // },

            // 'anomalyCause': { required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' },
            'anomalyOccurrenceDate': { required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' },
          },
        }
      },
    }
  },

  methods: {
    showNew(obj) {
      if (obj.disabledEditInfo != undefined) {
        this.disabledEditInfo = obj.disabledEditInfo
      }
      this['$refs']['reportDialog'].showNew({
        title: this.$tt('label_tms_waybill_submit_exception'),
        ...obj,
      })

    },



  }
}
</script>
